package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.domain.db.BlackList;
import com.tanhua.domain.db.UserInfo;
import com.tanhua.domain.vo.PageResult;
import com.tanhua.dubbo.mapper.BlackListMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 黑名单管理服务接口实现类
 */
@Service
public class BlackListApiImpl implements BlackListApi{
    @Autowired
    private BlackListMapper blackListMapper;

    /**
     * 黑名单 - 翻页列表
     */
    @Override
    public PageResult<UserInfo> queryBlackList(int page, int pagesize, Long userId) {
        Page dbPage = new Page(page, pagesize);
        //page分页参数 以及 userId  得到IPage分页结果对象
        IPage<UserInfo> ipage = blackListMapper.queryBlackList(dbPage, userId);
        return new PageResult<>(ipage.getTotal(), ipage.getSize(),
                ipage.getPages(), ipage.getCurrent(), ipage.getRecords());
    }

    /**
     * 黑名单 - 移除黑名单用户
     */
    @Override
    public void deleteBlackUser(Long blackUserId, Long userId) {
        QueryWrapper<BlackList> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("black_user_id",blackUserId);
        queryWrapper.eq("user_id",userId);
        blackListMapper.delete(queryWrapper);
    }
}
